<template>
  <div class="kidDetail">
    <!-- {{$route.params.id}}
    {{$route.params.kid}} -->

    <!-- 头部 -->
    <div class="top">
      <span @click="$router.push('/konwledge')">知识小册</span>
      <span class="separator">/</span>
      <span @click="$router.push(`/konwledge/${DetailPList.id}`)">{{ DetailPList.title }}</span>
      <span class="separator">/</span>
      <span>{{ DetailKList.title }}</span>
    </div>

    <div class="contain">
      <!-- 点赞、分享的组件 -->
      <Package DetailKList:="DetailKList" />

      <div class="left">
        <!-- 文章 -->
        <article>
          <div class="header">
            <h1>{{ DetailKList.title }}</h1>
            <p class="time">
              <span>发布于{{ DetailKList.publishAt | formatDate }}</span>
              <span> • </span>
              <span>阅读量{{ DetailKList.views }}</span>
            </p>
          </div>
          <div class="markdown">
            <div v-html="DetailKList.html" class="content"></div>
          </div>
          <div class="publish">
            发布于{{ DetailKList.publishAt | formatDate }} | 版权信息：<a
              href="https://creativecommons.org/licenses/by-nc/3.0/cn/deed.zh"
              >非商用-署名-自由转载</a
            >
          </div>
        </article>
        <!-- 评论 -->
        <div class="comment">
          <ComPub/>
        </div>
      </div>

      <div class="right">
        <div class="sticky">
          <KidRightTop />
          <!-- 楼层效果 -->
          <Floors />
        </div>
      </div>
      <BackTop />
    </div>
    <Footer />
  </div>
</template>

<script>
import { mapState, mapActions } from "vuex";
import KidRightTop from "@/components/Konwledge/KidRightTop.vue";
import Floors from "@/components/Konwledge/Floors.vue";
import BackTop from "@/components/BackTop.vue";
import Footer from "@/components/Footer.vue";
import Package from "@/components/Konwledge/Package.vue";
import ComPub from "@/components/About/Commentchild/ComPub";
export default {
  computed: {
    ...mapState({
      DetailKList: (state) => state.knowledge.DetailKList,
      DetailPList: (state) => state.knowledge.DetailPList,
    }),
  },
  methods: {
    ...mapActions({
      getKdetail: "knowledge/getKdetail",
      getPid: "knowledge/getDetail",
    }),
  },
  created() {
    this.getKdetail({ id: this.$route.params.id, kid: this.$route.params.kid });
    this.getPid({ id: this.$route.params.id });
  },
  mounted() {
    // console.log(this.DetailPList);
    // console.log(this.DetailKList,);
  },
  watch: {
    $route() {
      // console.log('arguments...', arguments);
      console.log(arguments[0].params.kid);
      console.log(arguments[1].params.kid);
      if (arguments[0].params.kid !== arguments[1].params.kid) {
        this.getKdetail({
          id: this.$route.params.id,
          kid: arguments[0].params.kid,
        });
      }
    },
  },
  components: {
    KidRightTop,
    Floors,
    BackTop,
    Footer,
    Package,
    ComPub,
  },
};
</script>

<style lang="scss">
.kidDetail {
  flex-direction: column;
  .contain {
    display: flex;
    flex: 1;
  }
}
.top {
  width: 100%;
  padding-top: 1rem;
  span {
    color: #000000d9 !important;
    font-size: 14px;
  }
  .separator {
    margin: 0 8px;
  }
}
.contain .left {
  article {
    padding: 1rem;
    background: var(--bg-second);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    h1 {
      text-align: center;
    }
    .time {
      margin-bottom: 1.2em;
      color: inherit;
      font-style: italic;
      text-align: center;
    }
  }
  .content {
    word-break: break-word;
    line-height: 1.75;
    font-weight: 400;
    font-size: 15px;
    overflow-x: hidden;
    letter-spacing: 1.2px;
    color: var(--main-text-color);
    h1 {
      text-align: left;
    }
    img {
      width: 100%;
      height: 100%;
    }
  }
  .content p {
    line-height: inherit;
    margin-top: 22px;
    margin-bottom: 22px;
  }
  .publish {
    color: #655e5e;
    font-size: 12px;
    line-height: 22px;
    text-align: center;
    margin-bottom: 21px;
    a {
      color: #655e5e;
      text-decoration: none;
      background-color: transparent;
      outline: none;
      cursor: pointer;
      transition: color 0.3s;
    }
  }
  .comment {
    box-shadow: var(--box-shadow);
    background: var(--bg-second);
    p {
      margin: 1rem 0;
      color: var(--main-text-color);
      font-weight: 500;
      font-size: 16px;
      line-height: 22px;
      text-align: center;
      letter-spacing: 0.06em;
    }
  }
}
.right .sticky {
  position: sticky;
  transform: translateY(0px);
  margin-top: 0px;
  top: 1rem;
  margin-bottom: 1rem;
}
</style>